home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / fakemode / fakemode.asm < prev    next >
Encoding:
Assembly Source File  |  1994-05-16  |  11.0 KB  |  643 lines

  1. ;// FAKEMODE.ASM  Assembler Routines Library for FakeMode
  2. ;// (c) 1993,94 by Yaka/Xography
  3. ;// V1.1; arranged 12.5.94
  4.  
  5. .model large
  6.  
  7. PUBLIC _F_settimer              ;//Timer routines.
  8. PUBLIC _F_gettimer
  9.  
  10. PUBLIC _F_isvga                 ;//FakeMode routines.
  11. PUBLIC _F_initgraph
  12. PUBLIC _F_closegraph
  13.  
  14. PUBLIC _F_videooff              ;//Display routines.
  15. PUBLIC _F_videoon
  16. PUBLIC _F_fadein
  17. PUBLIC _F_fadeout
  18. PUBLIC _F_fadeinfast
  19. PUBLIC _F_fadeoutfast
  20. PUBLIC _F_setlumi
  21.  
  22. PUBLIC _F_putbigpixel           ;//Pixel routines.
  23. PUBLIC _F_putsmallpixel
  24.  
  25.  
  26. .code
  27.  
  28. ;//---------------============ INTERNAL ROUTINES =============--------------
  29.  
  30. palette db 768 dup (?)
  31.  
  32. initpalette PROC
  33.   push di
  34.   push cs
  35.   pop es
  36.   mov di, offset palette
  37.   cld
  38.   mov dx,3c8h
  39.   xor ax,ax
  40.   xor bx,bx
  41.   out dx,al
  42.   inc dx                ;//ah=red, bh=green, bl=blue
  43.   mov cx,15
  44. initpal_outer:
  45.   push cx
  46.   mov cx,16
  47.   initpal_inner:
  48.       mov al,ah
  49.       out dx,al
  50.       stosb
  51.       mov al,bh
  52.       out dx,al
  53.       stosb
  54.       mov al,bl
  55.       out dx,al
  56.       stosb
  57.  
  58.       add ah,4
  59.     loop initpal_inner
  60.     mov ah,0
  61.     add bl,4
  62.     cmp bl,4
  63.     jne goon
  64.       add bl,4
  65.   goon:
  66.     pop cx
  67.   loop initpal_outer
  68.  
  69.   mov cx,16
  70.   xor ax,ax
  71.   xor bx,bx
  72. initpal_second:
  73.     mov al,ah
  74.     out dx,al
  75.     stosb
  76.     mov al,bh
  77.     out dx,al
  78.     stosb
  79.     mov al,bl
  80.     out dx,al
  81.     stosb
  82.     add bh,4
  83.   loop initpal_second
  84.   pop di
  85.   ret
  86. initpalette ENDP
  87.  
  88. setluminance PROC
  89. ;//Internal Routine to set one luminance value when fading in/out.
  90. ;//requires luminance value (0..255) in AL
  91. ;//Sets original VGA palette (256 colors)
  92. ;//Attention! Changes values of all general purpose registers (ax,bx,cx,dx)!
  93. ;//This routine is used in routines H_setlumi, H_fadein, H_fadeout.
  94.   mov bl,al  ;//luminance in bl
  95.   push ds
  96.   push cs
  97.   pop ds
  98.   push si
  99.   mov si, offset palette
  100.   push di
  101.   cld
  102.   mov dx,3c8h
  103.   mov di,3dah
  104.   mov al,0
  105.   out dx,al
  106.   inc dx
  107.   mov cx,256
  108. lumiloop:
  109.     lodsb
  110.     mul bl
  111.     mov al,ah
  112.     out dx,al
  113.     lodsb
  114.     mul bl
  115.     mov al,ah
  116.     out dx,al
  117.     lodsb
  118.     mul bl
  119.     mov al,ah
  120.  
  121.     push ax
  122.     xchg dx,di
  123.    lumjmp1:                     ;//wait for end of retrace
  124.      in al,dx
  125.      and al,00000001b
  126.     jnz lumjmp1
  127.    lumjmp2:                     ;//wait for retrace
  128.      in al,dx
  129.      and al,00000001b
  130.     jz lumjmp2
  131.     xchg dx,di
  132.     pop ax
  133.  
  134.     out dx,al
  135.   loop lumiloop
  136.   pop di
  137.   pop si
  138.   pop ds
  139.   ret
  140. setluminance ENDP
  141.  
  142. ;//------ TIMER
  143.  
  144. systimer dw 0
  145.  
  146. currentfloptime dw ?
  147.  
  148. currentpage dw 0
  149. currentsystimer dw 0
  150. alterint08 dw ?,?
  151.  
  152. switchpageint PROC
  153.   push ax
  154.   push bx
  155.   push dx
  156.  
  157.   inc word ptr systimer ;//set system timer
  158.  
  159.   mov bx,currentpage
  160.   add bx,32768
  161.   mov currentpage,bx
  162.   mov dx,3d4h
  163.   mov al,0ch            ;//set Start Adresse High (0Ch)
  164.   mov ah,bh
  165.   out dx,ax
  166.  
  167.   mov dx,3dah           ;//Wait for Retrace
  168. swretjmp:
  169.   in al,dx
  170.   and al,00001000b
  171.   jz swretjmp
  172.  
  173.   mov al,34h            ;//start Monoflop new
  174.   out 43h,al
  175.   mov ax,currentfloptime
  176.   out 40h,al
  177.   mov al,ah
  178.   out 40h,al
  179.  
  180.   mov bx,currentsystimer        ;//Test for Systemtimer call at 18.2 Hz
  181.   add ax,bx
  182.   mov currentsystimer,ax
  183.   cmp ax,bx
  184.   ja nosysroutine               ;//No --> continue
  185.   pop dx
  186.   pop bx
  187.   pop ax
  188.   jmp dword ptr alterint08      ;//call Systemtimer routine
  189. nosysroutine:
  190.   mov al,20h            ;//acknowledge interrupt controller
  191.   out 20h,al
  192.  
  193.   pop dx
  194.   pop bx
  195.   pop ax
  196.   iret
  197. switchpageint ENDP
  198.  
  199. counter dw 0
  200.  
  201. synchroint PROC
  202.   push ax
  203.   mov ax,counter
  204.   inc ax
  205.   mov counter,ax
  206.   mov al,20h
  207.   out 20h,al
  208.   pop ax
  209.   iret
  210. synchroint ENDP
  211.  
  212. inittimer PROC
  213.   push di
  214.   mov ax,1234h
  215.   mov currentfloptime,ax
  216.  
  217.   mov ax,3508h          ;//save old Interrupt 08
  218.   int 21h
  219.   mov alterint08,bx
  220.   mov alterint08+2,es
  221.  
  222.   xor ax,ax             ;//redirect Interrupt 08 to synchronisation routine
  223.   mov es,ax
  224.   mov di,08h*4
  225.   cli
  226.   cld
  227.   mov ax,offset synchroint
  228.   stosw
  229.   mov ax,cs
  230.   stosw
  231.   sti
  232.  
  233.   ;//------ measure Synchronisation
  234.  
  235.   mov dx,3dah           ;//Wait for End of Retrace
  236. s1endretjmp:
  237.   in al,dx
  238.   and al,00001000b
  239.   jnz s1endretjmp
  240. s1retjmp:                       ;//Wait for Retrace
  241.   in al,dx
  242.   and al,00001000b
  243.   jz s1retjmp
  244.  
  245. synchroback:
  246.  
  247.   mov al,36h
  248.   out 43h,al
  249.   mov ax,currentfloptime
  250.   out 40h,al
  251.   mov al,ah
  252.   out 40h,al
  253.  
  254.   mov ax,0
  255.   mov counter, ax
  256.  
  257.   mov dx,3dah           ;//Wait for End of Retrace
  258. s2endretjmp:
  259.   in al,dx
  260.   and al,00001000b
  261.   jnz s2endretjmp
  262. s2retjmp:               ;//Wait for Retrace
  263.   in al,dx
  264.   and al,00001000b
  265.   jz s2retjmp
  266.  
  267.   mov ax,counter
  268.   cmp ax,0
  269.   je fertig
  270.   mov ax,currentfloptime
  271.   add ax,250
  272.   mov currentfloptime,ax
  273.   jmp synchroback
  274.  
  275. fertig:
  276.   mov al,34h            ;//set Systemtimer correctly (Monoflop)
  277.   out 43h,al
  278.   mov ax, currentfloptime
  279.   sub ax,800
  280.   mov currentfloptime,ax
  281.   out 40h,al
  282.   mov al,ah
  283.   out 40h,al
  284.  
  285.   xor ax,ax             ;//redirect Interrupt 08 to Screenswitch routine
  286.   mov es,ax
  287.   mov di,08h*4
  288.   cli
  289.   cld
  290.   mov ax,offset switchpageint
  291.   stosw
  292.   mov ax,cs
  293.   stosw
  294.   sti
  295.   pop di
  296.   ret
  297. inittimer ENDP
  298.  
  299. closetimer PROC
  300.   push ds
  301.   push di
  302.   push si
  303.   cli
  304.   mov al,36h            ;//Systemtimer back to normal speed
  305.   out 43h,al
  306.   xor al,al
  307.   out 40h,al
  308.   out 40h,al
  309.   push cs               ;//restore interrupt vector back to normal
  310.   pop ds
  311.   mov si,offset alterint08
  312.   xor ax,ax
  313.   mov es,ax
  314.   mov di,08h*4
  315.   cld
  316.   movsw
  317.   movsw
  318.   sti
  319.   pop si
  320.   pop di
  321.   pop ds
  322.   ret
  323. closetimer ENDP
  324.  
  325. ;//---------------============ USER ROUTINES =============--------------
  326.  
  327. _F_settimer PROC
  328. ;//Sets timer variable to defined value. (timer variable is incremented
  329. ;// every vertical retrace)
  330. arg value:word
  331.   push bp
  332.   mov bp,sp
  333.   mov ax,value
  334.   mov systimer,ax
  335.   pop bp
  336.   ret
  337. _F_settimer ENDP
  338.  
  339. _F_gettimer PROC
  340. ;//Reads current value of timer variable.
  341.   mov ax,systimer
  342.   ret
  343. _F_gettimer ENDP
  344.  
  345.  
  346. _F_isvga PROC  ;//AX=0 = No VGA, AX=255 = is VGA, AX = 254 = unknown
  347. ;//Checks if VGA card is installed.
  348.   mov ax,1a00h
  349.   int 10h
  350.   cmp al,1ah
  351.   jne isnovga
  352.   cmp bl,07h
  353.   jb isnovga
  354.   xor ax,ax
  355.   cmp bl,08
  356.   ja isunknown
  357.   mov al,0ffh
  358.   ret
  359.  isunknown:
  360.   mov al,254d
  361.   ret
  362.  isnovga:
  363.   xor ax,ax
  364.   ret
  365. _F_isvga ENDP
  366.  
  367. oldvideomode db 3
  368.  
  369. _F_initgraph PROC
  370. ;//Initializes Fakemode, including palette and timer setup.
  371.   push di
  372.   mov ax,0f00h
  373.   int 10h
  374.   mov oldvideomode,al
  375.  
  376.   mov ax,0013h
  377.   int 10h
  378.  
  379.   mov dx,3ceh
  380.   mov al,5
  381.   out dx,al
  382.   inc dx
  383.   in al,dx
  384.   and al,11101111b
  385.   out dx,al
  386.   dec dx
  387.  
  388.   mov al,6
  389.   out dx,al
  390.   inc dx
  391.   in al,dx
  392.   and al,11111101b
  393.   out dx,al
  394.  
  395.   mov dx,3c4h
  396.   mov al,4
  397.   out dx,al
  398.   inc dx
  399.   in al,dx
  400.   and al,11110111b
  401.   or al,4
  402.   out dx,al
  403.  
  404.   mov ax,0a000h
  405.   mov es,ax
  406.   xor di,di
  407.   mov ax,di
  408.   mov cx,8000h
  409.   rep stosw
  410.  
  411.   mov dx,3d4h
  412.   mov al,9
  413.   out dx,al
  414.   inc dx
  415.   in al,dx
  416.   and al,01110000b
  417.   out dx,al
  418.   dec dx
  419.  
  420.   mov al,14h
  421.   out dx,al
  422.   inc dx
  423.   in al,dx
  424.   and al,10111111b
  425.   out dx,al
  426.   dec dx
  427.  
  428.   mov al,17h    ;//select Word-Mode (normally: Bytemode)
  429.   out dx,al
  430.   inc dx
  431.   in al,dx
  432.   and al,10111111b ;//normally: or al,01000000b
  433.   out dx,al
  434.  
  435.   call initpalette
  436.  
  437.   call inittimer
  438.   pop di
  439.   ret
  440. _F_initgraph ENDP
  441.  
  442. _F_closegraph PROC
  443. ;//Closes FakeMode and returns to previous video mode.
  444.   call closetimer
  445.   xor ax,ax
  446.   mov al,oldvideomode
  447.   int 10h
  448.   ret
  449. _F_closegraph ENDP
  450.  
  451.  
  452. _F_videooff PROC
  453. ;//Switches Screen off.
  454.   mov dx,3c4h
  455.   mov al,1
  456.   out dx,al
  457.   inc dx
  458.   in al,dx
  459.   or al,00100000b
  460.   out dx,al
  461.   ret
  462. _F_videooff ENDP
  463.  
  464. _F_videoon PROC
  465. ;//Switches screen on.
  466.   mov dx,3c4h
  467.   mov al,1
  468.   out dx,al
  469.   inc dx
  470.   in al,dx
  471.   and al,11011111b
  472.   out dx,al
  473.   ret
  474. _F_videoon ENDP
  475.  
  476. _F_fadein PROC
  477. ;//Fades screen in slowly. (Attention! Works only when Screen is switched on.
  478. ;// Use H_setlumi(0) to darken screen before fadein (instead of H_videooff)!)
  479.   mov ax,0
  480. fadeinloop:
  481.     push ax
  482.     call setluminance
  483.     pop ax
  484.     inc ax
  485.     cmp ax,256
  486.   jb fadeinloop
  487.   ret
  488. _F_fadein ENDP
  489.  
  490. _F_fadeout PROC
  491. ;//Fades out screen slowly.
  492.   mov ax,256
  493. fadeoutloop:
  494.     dec ax
  495.     push ax
  496.     call setluminance
  497.     pop ax
  498.     cmp ax,0
  499.   ja fadeoutloop
  500.   ret
  501. _F_fadeout ENDP
  502.  
  503. _F_fadeinfast PROC
  504. ;//Fades in screen with double speed
  505.   mov ax,0
  506. fadeinfastloop:
  507.     push ax
  508.     call setluminance
  509.     pop ax
  510.     add ax,2
  511.     cmp ax,256
  512.   jb fadeinfastloop
  513.   mov al,255
  514.   call setluminance
  515.   ret
  516. _F_fadeinfast ENDP
  517.  
  518. _F_fadeoutfast PROC
  519. ;//Fades out screen with double speed
  520.   mov ax,256
  521. fadeoutfastloop:
  522.     sub ax,2
  523.     push ax
  524.     call setluminance
  525.     pop ax
  526.     cmp ax,0
  527.   ja fadeoutfastloop
  528.   ret
  529. _F_fadeoutfast ENDP
  530.  
  531. _F_setlumi PROC
  532. ;//Sets screen luminance directly.
  533. arg lumi:byte
  534.   push bp
  535.   mov bp,sp
  536.   mov al,lumi
  537.   call setluminance
  538.   pop bp
  539.   ret
  540. _F_setlumi ENDP
  541.  
  542.  
  543. _F_putbigpixel PROC
  544. ;//Puts one pixel with 320x200 resolution (Actually there are 2 pixels at
  545. ;// 320x400 resolution)
  546.   ARG x:word, y:byte, red:byte, green:byte, blue:byte
  547.   push bp
  548.   mov bp,sp
  549.   push di
  550.   mov bx,x
  551.   mov cx,bx
  552.   and cl,00000011b      ;//calculate Bitplane...
  553.   mov dx,3c4h
  554.   mov ax,0102h
  555.   shl ah,cl
  556.   out dx,ax             ;//...and set it
  557.   mov ax,0a000h         ;//set dest segment
  558.   mov es,ax
  559.   mov ax,320            ;//set dest offset
  560.   mov dl,y
  561.   mov dh,0
  562.   mul dx
  563.   shr bx,1
  564.   and bl,11111110b
  565.   add bx,ax             ;//bx contains basic offset
  566.   mov di,bx
  567.   mov al,blue           ;//calculate red-blue
  568.   mov ah,16
  569.   mul ah
  570.   cmp ax,0
  571.   je bpixgoon
  572.     sub ax,16
  573. bpixgoon:
  574.   add al,red
  575.   mov ah,green
  576.   add ah,240
  577.   and cl,00000001b
  578.   jz typetwo
  579.     mov es:[di+160],ax
  580.     xchg ah,al
  581.     mov es:[di],ax
  582.     jmp tend
  583. typetwo:
  584.     mov es:[di],ax
  585.     xchg ah,al
  586.     mov es:[di+160],ax
  587.     jmp tend
  588. tend:
  589.   pop di
  590.   pop bp
  591.   ret
  592. _F_putbigpixel ENDP
  593.  
  594. _F_putsmallpixel PROC
  595. ;//Puts one pixel with 320x400 resolution.
  596.   ARG x:word, y:word, red:byte, green:byte, blue:byte
  597.   push bp
  598.   mov bp,sp
  599.   push di
  600.   mov bx,x
  601.   mov cx,bx
  602.   and cl,00000011b      ;//calculate Bitplane...
  603.   mov dx,3c4h
  604.   mov ax,0102h
  605.   shl ah,cl
  606.   out dx,ax             ;//...and set it
  607.   mov ax,0a000h         ;//set destination segment
  608.   mov es,ax
  609.   mov ax,160            ;//set destination offset
  610.   mov dx,y
  611.   mul dx
  612.   shr bx,1
  613.   and bl,11111110b
  614.   add bx,ax             ;//bx contains basic offset
  615.   mov di,bx
  616.   mov al,blue           ;//calculate red-blue
  617.   mov ah,16
  618.   mul ah
  619.   cmp ax,0
  620.   je spixgoon
  621.     sub ax,16           ;//This is where i adapt blue values.
  622. spixgoon:
  623.   add al,red
  624.   add cx,y
  625.   and cl,00000001b
  626.   jz stypetwo           ;//Here i decide whether to put red/blue on page 1
  627.     mov ah,al           ;//and green on page 2 OR to put green on page 1
  628.     mov al,green        ;//and red/blue on page 2.
  629.     add al,240
  630.     mov es:[di],ax
  631.     jmp send
  632. stypetwo:
  633.     mov ah,green
  634.     add ah,240
  635.     mov es:[di],ax
  636. send:
  637.   pop di
  638.   pop bp
  639.   ret
  640. _F_putsmallpixel ENDP
  641.  
  642. END
  643.